<template>
  <div id="app" class="wrapper wrapper-content animated fadeInRight v-cloak" v-cloak>
    <div class="row">
      <div class="ibox float-e-margins">
        <div class="ibox-content col-md-12">
          <form id="pumpGateForm" method="post" class="form m-t" @submit.prevent="save()" accept-charset="UTF-8">
            <input type="hidden" name="id" v-model="item.id"/>
            <input type="hidden" name="token" v-model="item.token"/>
            <input type="hidden" name="newFlag" v-model="newFlag"/>
            <div class="clearfix "></div>
            <div class="col-md-6 b-r">

              <div class="form-group clearfix">
                <label class="col-md-8 control-label">站点编码：</label>
                <div class="col-md-12">
                  <input id="bean-code" name="code" v-model="item.code" class="form-control" type="text"
                      placeholder="请输入站点编码" required="" aria-required="true" aria-describedby="bean-code-error"
                      maxlength="50" aria-invalid="true">
                  <span id="bean-code-error" class="help-block m-b-none" for="bean-code"></span>
                </div>
              </div>

              <div class="form-group clearfix">
                <label class="col-md-8 control-label">站点名称：</label>
                <div class="col-md-12">
                  <input id="bean-name" name="name" v-model="item.name" class="form-control" type="text"
                      placeholder="请输入站点名称" required="" aria-required="true" aria-describedby="bean-name-error"
                      maxlength="50" aria-invalid="true">
                  <span id="bean-name-error" class="help-block m-b-none" for="bean-name"></span>
                </div>
              </div>

              <div class="form-group clearfix">
                <label class="col-md-8 control-label">所在河道：</label>
                <div class="col-md-12">
                  <!--<input id="bean-riverCourseCode" name="riverCourseCode" v-model="item.riverCourseCode"-->
                  <!--class="form-control" type="text" placeholder="请输入所在河道" required="" aria-required="true"-->
                  <!--aria-describedby="bean-riverCourseCode-error" maxlength="50" aria-invalid="true">-->
                  <riverSelect :selected-code="item.riverCourseCode"/>
                  <span id="bean-riverCourseCode-error" class="help-block m-b-none" for="bean-riverCourseCode"></span>
                </div>
              </div>

              <div class="form-group clearfix">
                <label class="col-md-8 control-label">类型：</label>
                <div class="col-md-12">
                  <input id="bean-type" name="type" v-model="item.type" class="form-control" type="text"
                      placeholder="请输入类型" required="" aria-required="true" aria-describedby="bean-type-error"
                      maxlength="50" aria-invalid="true">
                  <span id="bean-type-error" class="help-block m-b-none" for="bean-type"></span>
                </div>
              </div>

              <div class="form-group clearfix">
                <label class="col-md-8 control-label">行政区划：</label>
                <div class="col-md-12">
                  <!--<input id="bean-regionId" name="regionId" v-model="item.regionId" class="form-control" type="text"-->
                  <!--placeholder="请输入行政区划" aria-describedby="bean-regionId-error" maxlength="50"-->
                  <!--aria-invalid="true">-->
                  <region-select :region-ids="item.regionId"/>
                  <span id="bean-regionId-error" class="help-block m-b-none" for="bean-regionId"></span>
                </div>
              </div>

              <div class="form-group clearfix">
                <label class="col-md-8 control-label">所在经度：<a href="javascript:;" @click="getCoordinate()"
                    class="label label-success"><i
                    class="fa fa-coordinate"></i>坐标拾取</a></label>
                <div class="col-md-12">
                  <input id="bean-longitude" name="longitude" v-model="item.longitude" class="form-control"
                      type="number"
                      placeholder="请输入所在经度" required="" aria-required="true" aria-describedby="bean-longitude-error"
                      aria-invalid="true">
                  <span id="bean-longitude-error" class="help-block m-b-none" for="bean-longitude"></span>
                </div>
              </div>

              <div class="form-group clearfix">
                <label class="col-md-8 control-label">所在纬度：</label>
                <div class="col-md-12">
                  <input id="bean-latitude" name="latitude" v-model="item.latitude" class="form-control" type="number"
                      placeholder="请输入所在纬度" required="" aria-required="true" aria-describedby="bean-latitude-error"
                      aria-invalid="true">
                  <span id="bean-latitude-error" class="help-block m-b-none" for="bean-latitude"></span>
                </div>
              </div>

              <div class="form-group clearfix">
                <label class="col-md-8 control-label">建成时间：</label>
                <div class="col-md-12">
                  <input id="bean-completionTime" name="completionTime" v-model="item.completionTime"
                      class="laydate-icon form-control layer-date" type="text" placeholder="请输入建成时间" required=""
                      aria-required="true" aria-describedby="bean-completionTime-error" aria-invalid="true">
                  <span id="bean-completionTime-error" class="help-block m-b-none" for="bean-completionTime"></span>
                </div>
              </div>
              <div class="form-group clearfix">
                <label class="col-md-8 control-label">工程等级：</label>
                <div class="col-md-12">
                  <input id="bean-engineeringLevel" name="engineeringLevel" v-model="item.engineeringLevel"
                      class="form-control" type="number" placeholder="请输入工程等级"
                      aria-describedby="bean-engineeringLevel-error" aria-invalid="true">
                  <span id="bean-engineeringLevel-error" class="help-block m-b-none" for="bean-engineeringLevel"></span>
                </div>
              </div>

            </div>
            <div class="col-md-6">

              <div class="form-group clearfix">
                <label class="col-md-8 control-label">建筑物等级：</label>
                <div class="col-md-12">
                  <input id="bean-buildingLevel" name="buildingLevel" v-model="item.buildingLevel" class="form-control"
                      type="text" placeholder="请输入建筑物等级" aria-describedby="bean-buildingLevel-error" maxlength="50"
                      aria-invalid="true">
                  <span id="bean-buildingLevel-error" class="help-block m-b-none" for="bean-buildingLevel"></span>
                </div>
              </div>

              <div class="form-group clearfix">
                <label class="col-md-8 control-label">闸门/水泵数量：</label>
                <div class="col-md-12">
                  <input id="bean-pumpsNumber" name="pumpsNumber" v-model="item.pumpsNumber" class="form-control"
                      type="number" placeholder="请输入闸门/水泵数量" required="" aria-required="true"
                      aria-describedby="bean-pumpsNumber-error" aria-invalid="true">
                  <span id="bean-pumpsNumber-error" class="help-block m-b-none" for="bean-pumpsNumber"></span>
                </div>
              </div>

              <div class="form-group clearfix">
                <label class="col-md-8 control-label">节制闸过闸流量/装机流量(m³/s)：</label>
                <div class="col-md-12">
                  <input id="bean-sluiceFlow" name="sluiceFlow" v-model="item.sluiceFlow" class="form-control"
                      type="number" placeholder="请输入节制闸过闸流量/装机流量(m³/s)" required="" aria-required="true"
                      aria-describedby="bean-sluiceFlow-error" aria-invalid="true">
                  <span id="bean-sluiceFlow-error" class="help-block m-b-none" for="bean-sluiceFlow"></span>
                </div>
              </div>

              <div class="form-group clearfix">
                <label class="col-md-8 control-label">闸门总净宽/设计扬程(m)：</label>
                <div class="col-md-12">
                  <input id="bean-gateWidth" name="gateWidth" v-model="item.gateWidth" class="form-control"
                      type="number"
                      placeholder="请输入闸门总净宽/设计扬程(m)" required="" aria-required="true"
                      aria-describedby="bean-gateWidth-error" aria-invalid="true">
                  <span id="bean-gateWidth-error" class="help-block m-b-none" for="bean-gateWidth"></span>
                </div>
              </div>

              <div class="form-group clearfix">
                <label class="col-md-8 control-label">装机功率(kw)：</label>
                <div class="col-md-12">
                  <input id="bean-installedPower" name="installedPower" v-model="item.installedPower"
                      class="form-control" type="number" placeholder="请输入装机功率(kw)" required="" aria-required="true"
                      aria-describedby="bean-installedPower-error" aria-invalid="true">
                  <span id="bean-installedPower-error" class="help-block m-b-none" for="bean-installedPower"></span>
                </div>
              </div>

              <div class="form-group clearfix">
                <label class="col-md-8 control-label">水闸管理单位名称：</label>
                <div class="col-md-12">
                  <input id="bean-management" name="management" v-model="item.management" class="form-control"
                      type="text" placeholder="请输入水闸管理单位名称" aria-describedby="bean-management-error" maxlength="50"
                      aria-invalid="true">
                  <span id="bean-management-error" class="help-block m-b-none" for="bean-management"></span>
                </div>
              </div>

              <div class="form-group clearfix">
                <label class="col-md-8 control-label">站点地址：</label>
                <div class="col-md-12">
                  <input id="bean-siteAddress" name="siteAddress" v-model="item.siteAddress" class="form-control"
                      type="text" placeholder="请输入站点地址" required="" aria-required="true"
                      aria-describedby="bean-siteAddress-error" maxlength="50" aria-invalid="true">
                  <span id="bean-siteAddress-error" class="help-block m-b-none" for="bean-siteAddress"></span>
                </div>
              </div>

              <div class="form-group clearfix">
                <label class="col-md-8 control-label">备注：</label>
                <div class="col-md-12">
                  <input id="bean-memo" name="memo" v-model="item.memo" class="form-control" type="text"
                      placeholder="请输入备注" aria-describedby="bean-memo-error" maxlength="255" aria-invalid="true">
                  <span id="bean-memo-error" class="help-block m-b-none" for="bean-memo"></span>
                </div>
              </div>

            </div>

            <div class="clearfix "></div>
            <div class="col-12 text-center" style="height: 50px;">
              <div>
                <input class="btn btn-primary" type="submit" value="保存"/> | <a @click="lbox.closeMyBoxLayer()" class="btn btn-danger" href="javascript:">返回</a>
              </div>
            </div>
          </form>
        </div>
      </div>
    </div>
  </div>
</template>
<script type="text/javascript">
import '@/assets/css/style.css'

import $ from '@/assets/js/jquery-vendor.js'
import 'jquery.cookie'
import axios from 'axios'
import '@/assets/js/validate/validation-vendor.js'

import 'layui-laydate/dist/theme/default/laydate.css'
import laydate from 'layui-laydate'
import {apiUtil, axiosContentType, site} from '@/assets/js/boss'
import riverSelect from './riverSelect'
import regionSelect from './regionSelect'

export default {
  data() {
    return {
      item: {},
      newFlag: 0,
      uuidToken: ''
    }
  },
  components: {
    riverSelect,
    regionSelect
  },
  mounted() {
    let that = window.$vueApp = this;
    document.getElementsByTagName('body')[0].className = 'fixed-sidebar full-height-layout';
    $('#pumpGateForm').validate();
    that.staff.init(function () {
      that.newFlag = sessionStorage.getItem(site.pumpGate.info);
      if (that.newFlag) that.uuidToken = apiUtil.guid();
      if (apiUtil.existSessionKey(site.pumpGate.info)) {
        that.info();
      }
    });

    laydate.render({elem: '#bean-completionTime', event: 'click', type: 'datetime', format: 'yyyy-MM-dd HH:mm:ss'});
  },
  methods: {
    info() {
      let that = window.$vueApp = this;
      axios.get(site.pumpGate.info + sessionStorage.getItem(site.pumpGate.info), {}).then(function (response) {
        const result = response.data;
        if (result.code === 0) {
          that.item = result.data;
        } else {
          alert(result.message);
        }
      });
    },
    save() {
      let that = window.$vueApp = this;
      if ($('#pumpGateForm').valid()) {
        axios.post(site.pumpGate.save, $('#pumpGateForm').serialize(),
            axiosContentType.xWwwFormUrlencoded).then(function (response) {
          const result = response.data;
          // console.info("获取数据.." + JSON.stringify(result));
          if (result.code === 0) {
            parent.$vueApp.page();
            alert('保存成功!');
            that.lbox.closeMyBoxLayer()
          } else {
            alert(result.message);
          }
        });
      }
      ;
    },
    getCoordinate() { // 坐标拾取页面
      let that = window.$vueApp = this;
      that.lbox.openMyBoxLayer('经纬度坐标拾取', site.map.mapll);
    },
    setMapSite(longitude, latitude, address) { // 坐标拾取回调
      let that = window.$vueApp = this;
      $('#bean-longitude').val(longitude);
      $('#bean-latitude').val(latitude);
      that.item.longitude = longitude;
      that.item.latitude = latitude;
    }
  }
}
</script>

